<?php

namespace App\Models\templates;

/**
 * 后台专用模型
 * Class ShippingTemplateAdmin
 *
 * @package App\Models\templates
 * @property int $id 编号
 * @property string $name 模板名称
 * @property int $type 计费方式  1 =>按件数  2=>按重量  3=>按体积
 * @property int $appoint 指定包邮  1开启0关闭
 * @property int $sort 排序
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read mixed $column_name
 * @property-read mixed $region_tables
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin whereAppoint($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplateAdmin whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class ShippingTemplateAdmin extends ShippingTemplate
{
    protected $fillable = [
        'name',
        'type',
        'appoint',
        'sort',
    ];

    protected $appends = [
        'column_name'
    ];

    public function getColumnNameAttribute($value)
    {
        $empty[] = [
            'city' => '0',
            'name' => '全国',
            'decs' => 2
        ];

        return array_values(json_decode($value, true) ?: $empty);
    }

}
